//
//  DZMainViewController.swift
//  dazhanweibo
//
//  Created by apple on 16/2/27.
//  Copyright © 2016年 apple. All rights reserved.
//

import UIKit

class DZMainViewController: UITabBarController ,DZMainTabBarDelegate {

    override func viewDidLoad() {
        super.viewDidLoad()

        let mainTabBar = DZMainTabBar()
        
        mainTabBar.composeDelegate = self
        
        setValue(mainTabBar, forKey: "tabBar")
        
        // Do any additional setup after loading the view.
        addChildViewControllers()
    }

    func mainTabBarComposeClick() {
        print("test")
    }
    func addChildViewControllers() {
        let homeVC = DZHomeViewController()
        addChildViewController(homeVC, title: "首页", imageName: "tabbar_home")
        
        let messageVC = DZMessageViewController()
        addChildViewController(messageVC, title: "消息", imageName: "tabbar_message_center")
        
        //占位的tabBar
        addChildViewController(UIViewController())
        
        let discoverVC = DZDiscoverViewController()
        addChildViewController(discoverVC, title: "发现", imageName: "tabbar_discover")
        
        let profileVC = DZProfileViewController()
        addChildViewController(profileVC, title: "我的", imageName: "tabbar_profile")
        
    }
    
    func addChildViewController(childController: UIViewController , title :String , imageName :String) {
        childController.title = title
        childController.tabBarItem.image = UIImage(named: imageName)
        let hightedImageName = imageName + "_highlighted"
        childController.tabBarItem.selectedImage = UIImage(named: hightedImageName)?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        
        childController.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName : UIColor.orangeColor()], forState: UIControlState.Selected)
        
        addChildViewController(UINavigationController(rootViewController: childController))
    }
}
